{extend name="public:_base" /}
{block name="css"}
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/treemenu.css"/>
<style type="text/css">
    input[type="checkbox"] {
        zoom: 130%;
        margin-top: 0px;
    }

    .w40x {
        width: 20px;
        height: 18px;
        float: left;
        position: relative;
        margin-right: 5px;
    }
    .w40xc {
        margin-right: 25px;
    }
    .w40x:before {
        content: '';
        position: absolute;
        top: -15px;
        left: 50%;
        width: 1px;
        height: 24px;
        background: #ccc;
    }
    .w40x:after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 50%;
        height: 1px;
        background: #ccc;
    }
    .w40xc:after {
        width: 150%;
    }
    #treet1 tr:hover {
        background: #d6d6d6;
    }
</style>
{/block}

{block name="main"}
<div class="page-container">

    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn radius btn-primary" onclick="edit('添加模块','{:url('Nav/edit',['type'=>'model'])}')" href="javascript:;">
                <i class="Hui-iconfont">&#xe600;</i> 添加栏目
            </a>

            <a class="btn radius btn-primary" onclick="edit('添加单页面','{:url('Nav/edit',['type'=>'one'])}')" href="javascript:;">
                <i class="Hui-iconfont">&#xe600;</i> 添加单页面
            </a>

            <a class="btn radius btn-primary" onclick="edit('添加外部链接','{:url('Nav/edit',['type'=>'link'])}')" href="javascript:;">
                <i class="Hui-iconfont">&#xe600;</i> 添加外部链接
            </a>
        </span>

    </div>

    <div class="mt-10">

        <!-- 内容头部 -->
        <div class="tree-title">
            <span></span>
            <span>名称</span>
            <span>类型</span>
            <span>状态</span>
            <span>排序</span>
            <span>操作</span>
        </div>
        <!-- #内容头部 -->

        <!-- 内容 -->
        <ul class="tree">

            {foreach name="auth_rule" item="vo"}
            <li>
                <span class="item-box">
                    <span>{$vo.name}</span>
                    <span class="{$vo.model}"><font color="#FF0000">外部链接</font></span>
                    <span>{$vo.status|status=$vo.id}</span>
                    <span>{$vo.sort|sortby=$vo.id}</span>
                    <span class="tree-option">
                        {switch name="vo.type"}
                    {case value="model"}
                    {eq name="vo.model" value="index"}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled"
                       href="{:url(\'index/'.$vo.model.'/index',['navid'=>$vo.id])}" target="_blank"
                       title="查看">查看</a>
                    {else/}
                    <!--<a style="text-decoration:none" class="btn radius btn-xs btn-success"-->
                       <!--onClick="edit('发布-{$vo.name}','{:url(\''.$vo.model.'/index',['cid'=>$vo.id])}','10001')"-->
                       <!--href="javascript:;"-->
                       <!--title="发布">发布</a>-->
                        <a style="text-decoration:none" class="btn radius btn-xs btn-success" data-title="发布-{$vo.name}" data-href="{:url(\''.$vo.model.'/index',['cid'=>$vo.id])}" onclick="Hui_admin_tab(this)" href="javascript:;">发布</a>

                    {/eq}
                    {/case}
                    {case value="one"}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled {empty name="vo.status"}btn-default{/empty}"
                    href="{:url(\'index/'.$vo.model.'/index',['navid'=>$vo.id])}" target="_blank" disabled="disabled" {empty name="vo.status"}onclick="return false"{/empty}
                    title="查看">查看</a>
                    {/case}
                    {default /}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled"
                       href="{$vo.link}" target="_blank"
                       title="查看">查看</a>
                    {/switch}
                        <a style="text-decoration:none" class="btn radius btn-xs btn-warning"
                       onClick="edit('{$vo.name}编辑','{:url('Nav/edit',['type'=>$vo.type,'id'=>$vo.id])}','10001')" href="javascript:;"
                       title="编辑">编辑</a>
                        <!--<a style="text-decoration:none" class="btn radius btn-xs btn-danger"-->
                           <!--onClick="del_old(this,'{:url('Nav/del',['model'=>$vo.model,'id'=>$vo.id])}','10001')" href="javascript:;"-->
                           <!--title="删除">删除</a>-->
                        <a style="text-decoration:none" class="btn radius btn-xs btn-danger"
                           onClick="del('{:url('Nav/del',['model'=>$vo.model])}',{$vo.id})" href="javascript:;" title="删除">删除</a>

                    </span>
                </span>
                {foreach name="vo['child']" item="n"}
                <ul>
                    <li>
                                <span class="item-box">
                                    <span>{$n.name}</span>
                                    <span class="{$n.model}"><font color="#FF0000">外部链接</font></span>
                                    <span>{$n.status|status=$n.id}</span>
                                    <span>{$n.sort|sortby=$n.id}</span>
                                    <span class="tree-option">
                                        {switch name="n.type"}
                    {case value="model"}
                    {eq name="n.model" value="index"}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled"
                       href="{:url(\'index/'.$n.model.'/index',['navid'=>$n.id])}" target="_blank"
                       title="查看">查看</a>
                    {else/}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-success" data-title="发布-{$n.name}" data-href="{:url(\''.$n.model.'/index',['cid'=>$n.id])}" onclick="Hui_admin_tab(this)" href="javascript:;">发布</a>

                    <!--<a style="text-decoration:none" class="btn radius btn-xs btn-success"-->
                       <!--onClick="edit('发布-{$n.name}','{:url(\''.$n.model.'/index',['cid'=>$n.id])}','10001')"-->
                       <!--href="javascript:;"-->
                       <!--title="发布">发布</a>-->
                    {/eq}
                    {/case}
                    {case value="one"}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled {empty name="n.status"}btn-default{/empty}"
                    href="{:url(\'index/'.$n.model.'/index',['navid'=>$n.id])}" target="_blank" disabled="disabled" {empty name="n.status"}onclick="return false"{/empty}
                    title="查看">查看</a>
                    {/case}
                    {default /}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled"
                       href="{$n.link}" target="_blank"
                       title="查看">查看</a>
                    {/switch}
                                        <a style="text-decoration:none" class="btn radius btn-xs btn-warning"
                       onClick="edit('{$n.name}编辑','{:url('Nav/edit',['type'=>$n.type,'id'=>$n.id])}','10001')" href="javascript:;"
                       title="编辑">编辑</a>
                        <!--<a style="text-decoration:none" class="btn radius btn-xs btn-danger"-->
                           <!--onClick="del_old(this,'{:url('Nav/del',['model'=>$n.model,'id'=>$n.id])}','10001')" href="javascript:;"-->
                           <!--title="删除">删除</a>-->
                                        <a style="text-decoration:none" class="btn radius btn-xs btn-danger"
                                           onClick="del('{:url('Nav/del',['model'=>$n.model])}',{$n.id})" href="javascript:;" title="删除">删除</a>

                                    </span>
                                </span>
                        {foreach name="n['child']" item="nn"}
                        <ul>
                            <li>
                                <span class="item-box">
                                    <span>{$nn.name}</span>
                                    <span class="{$nn.model}"><font  color="#FF0000">外部链接</font></span>
                                    <span>{$nn.status|status=$nn.id}</span>
                                    <span>{$nn.sort|sortby=$nn.id}</span>
                                    <span class="tree-option">
                                        {switch name="nn.type"}
                    {case value="model"}
                    {eq name="nn.model" value="index"}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled"
                       href="{:url(\'index/'.$nn.model.'/index',['navid'=>$nn.id])}" target="_blank"
                       title="查看">查看</a>
                    {else/}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-success" data-title="发布-{$nn.name}" data-href="{:url(\''.$nn.model.'/index',['cid'=>$nn.id])}" onclick="Hui_admin_tab(this)" href="javascript:;">发布</a>

                    <!--<a style="text-decoration:none" class="btn radius btn-xs btn-success"-->
                       <!--onClick="edit('发布-{$nn.name}','{:url(\''.$nn.model.'/index',['cid'=>$nn.id])}','10001')"-->
                       <!--href="javascript:;"-->
                       <!--title="发布">发布</a>-->
                    {/eq}
                    {/case}
                    {case value="one"}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled {empty name="nn.status"}btn-default{/empty}"
                    href="{:url(\'index/'.$nn.model.'/index',['navid'=>$nn.id])}" target="_blank" disabled="disabled" {empty name="nn.status"}onclick="return false"{/empty}
                    title="查看">查看</a>
                    {/case}
                    {default /}
                    <a style="text-decoration:none" class="btn radius btn-xs btn-disabled"
                       href="{$nn.link}" target="_blank"
                       title="查看">查看</a>
                    {/switch}
                                        <a style="text-decoration:none" class="btn radius btn-xs btn-warning"
                       onClick="edit('{$nn.name}编辑','{:url('Nav/edit',['type'=>$nn.type,'id'=>$nn.id])}','10001')" href="javascript:;"
                       title="编辑">编辑</a>
                        <!--<a style="text-decoration:none" class="btn radius btn-xs btn-danger"-->
                           <!--onClick="del_old(this,'{:url('Nav/del',['model'=>$nn.model,'id'=>$nn.id])}','10001')" href="javascript:;"-->
                           <!--title="删除">删除</a>-->
                                        <a style="text-decoration:none" class="btn radius btn-xs btn-danger"
                                           onClick="del('{:url('Nav/del',['model'=>$nn.model])}',{$nn.id})" href="javascript:;" title="删除">删除</a>

                                    </span>
                                </span>
                            </li>
                        </ul>
                        {/foreach}
                    </li>
                </ul>
                {/foreach}
            </li>
            {/foreach}

        </ul>
        <!-- #内容 -->

    </div>
</div>
</div>













<div class="page-container">
    <form method="post">
        <div class="flexigrid">
            <div class="mDiv">
                <div class="ftitle">
                    <h3>栏目列表(共{$arctype_list|count}条记录)</h3>
                </div>
            </div>

            <div id="flexigrid" class="bDiv" style="height: auto;">
                {empty name="arctype_list"}
                <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                    <table>
                        <tbody>
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <i class="fa fa-exclamation-circle"></i>没有符合条件的记录
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="iDiv" style="display: none;"></div>
                {else /}
                <table class="table table-border table-bg" cellpadding="0" cellspacing="0" border="0" id="arctype_table" style="width: 100%">
                    <thead>
                    <tr>
                        <th axis="col3" class="w60">
                            <div class="sundefined tc">ID</div>
                        </th>
                        <th axis="col3" class="">
                            <div class="sundefined" >
                                <img src="__STATIC__/admin/images/tv-expandable.gif" id="all_treeclicked" title="关闭所有子栏目" style="float: none;" data-status="close" onClick="treeClicked(this,'all',0);">
                                栏目名称
                            </div>
                        </th>
                        <th axis="col2" class="w100">
                            <div class="tc">所属模型</div>
                        </th>
                        <th axis="col2" class="w60">
                            <div>隐藏</div>
                        </th>
                        <th axis="col1" class="w300">
                            <div class="tl" style="text-indent: 6px">操作</div>
                        </th>
                        <th axis="col2" class="w60">
                            <div class="tc">排序</div>
                        </th>
                    </tr>
                    </thead>
                    <tbody id="treet1">
                    {foreach name="arctype_list" item="vo" key="k" }
                    <tr nctype="0" {if condition="$vo['pid'] gt 0"} style="display:none;"{/if} class="pid_{$vo['pid']}" data-level="{$vo['level']}" data-id="{$vo['id']}">
                    <td class="name">
                        <div class="w60 tc">
                            {$vo.id}
                        </div>
                    </td>
                    <td class="name" style="width: 40%">
                        <div>
                            {gt name='vo.level' value='0'}
                            {php}
                            if (1 == $vo['level']) {
                            echo '<span class="w40x"></span>';
                            } elseif (2 == $vo['level']) {
                            echo '<span class="w40x w40xc"></span>';
                            }
                            {/php}
                            {/gt}

                            {gt name="vo.has_children" value="0"}
                            <img src="__STATIC__/admin/images/tv-expandable.gif" style="float: none;" fieldid="2" status="open" nc_type="flex" onClick="treeClicked(this,{$vo['id']},0);" class="has_children">
                            {else /}
                            <img src="__STATIC__/admin/images/tv-collapsable-last.gif" style="float: none;" fieldid="2" status="open" nc_type="flex">
                            {/gt}

                            {$vo.name}
                            {if condition="($vo.type eq 'model') and ($vo.model neq 'index')"}
                                <i class="arctotal">（文档：{$vo.id|get_total_arc=###,$vo.model}条）</i>
                            {/if}
                        </div>
                    </td>
                    <td class="sort">
                        <div class="w100 tc">
                            {notempty name="$nav_model[$vo.model]"}
                            {$nav_model[$vo.model]??''}
                            {else}
                            <span class="{$vo.model}"><font color="#FF0000">外部链接</font></span>
                            {/notempty}
                        </div>
                    </td>

                    <td align="center" class="">
                        <div class="w60">
                            {$vo.status|status=$vo.id}
                        </div>
                    </td>
                    <td>
                        <div class="w300 tl pb0">
                            {if condition="$vo['type'] eq 'model'" /}

                                {eq name="$vo.model" value="index"}
                                <a href="{:url(\'index/'.$vo.model.'/index',['navid'=>$vo.id])}" class="btn radius blue"  target="_blank"><i class="fa fa-pencil-square-o"></i>查看</a>
                                {else/}
                                <a data-href="{:url($vo['model'].'/index',['cid'=>$vo.id])}" class="btn radius btn-primary"  data-title="发布-{$vo.name}" onclick="Hui_admin_tab(this)" href="javascript:;"><i class="fa fa-pencil-square-o"></i>内容</a>
                                {/eq}

                            {elseif condition="$vo['type'] eq 'one'"/}
                                {empty name="$vo.link"}
                                    <a href="{:url(\'index/'.$vo.model.'/index',['navid'=>$vo.id])}" class="btn radius blue"  target="_blank"><i class="fa fa-pencil-square-o"></i>查看</a>
                                {else/}
                                    <a href="{$vo['link']|nav_link}" class="btn radius blue"  target="_blank"><i class="fa fa-pencil-square-o"></i>查看</a>
                                {/empty}
                            {else /}
                                <a href="{$vo['link']}" class="btn radius blue"  target="_blank"><i class="fa fa-pencil-square-o"></i>查看</a>
                            {/if}

                            <a 11href="{:url('Nav/edit',['type'=>$vo.type,'id'=>$vo.id])}" class="btn radius btn-xs btn-warning" onClick="edit('{$vo.name}编辑','{:url('Nav/edit',['type'=>$vo.type,'id'=>$vo.id])}','10001')" href="javascript:;"><i class="fa fa-pencil-square-o"></i>编辑</a>

                            <a class="btn radius btn-xs btn-danger"  href="javascript:void(0);" data-url="{:url('Nav/del',['model'=>$vo.model])}" data-id="{$vo.id}" data-name="{$vo.name}" data-deltype="pseudo" onClick="delfun(this);"><i class="fa fa-trash-o"></i>删除</a>

                            {eq name="$vo.type" value="link"}
                                <a href="{$vo.link}" class="btn radius blue" target="_blank"><i class="fa fa-pencil-square-o"></i>浏览</a>
                            {else/}
                                <a href="{notempty name="$vo.link"}{$vo.link|nav_link} {else/}{:url(\'index/'.$vo['model'].'/index', ['navid' => $vo['id']])}{/notempty}" class="btn radius blue" target="_blank"><i class="fa fa-pencil-square-o"></i>浏览</a>
                            {/eq}
                        </div>
                    </td>
                    <td class="sort">
                        <div class="w60 tc pb0">
                            {$vo.sort|sortby=$vo.id}
                        </div>
                    </td>

                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                {/empty}
            </div>
        </div>
    </form>
    <script type="text/javascript">

        $(document).ready(function(){
            // 表格行点击选中切换
            $('#flexigrid > table>tbody >tr').click(function(){
                $(this).toggleClass('trSelected');
            });

            // 点击刷新数据
            $('.fa-refresh').click(function(){
                location.href = location.href;
            });

            treeClicked($('#all_treeclicked'), 'all', 1);
        });

        // 点击展开 收缩节点
        function treeClicked(obj,id,reload){
            if (id == 'all') {
                if (1 == reload) {
                    var status = getCookie('admin-treeClicked');
                    if (!status) {
                        status = $(obj).attr('data-status');
                    }
                } else {
                    var status = $(obj).attr('data-status');
                }
                if (status == 'close') {
                    $('tr[class^=pid_]').show().find('img').attr('src', '__STATIC__/admin/images/tv-collapsable-last.gif');
                    $(obj).attr('data-status', 'open').attr('title','关闭所有子栏目').attr('src','__STATIC__/admin/images/tv-collapsable-last.gif');
                } else {
                    $('tr[data-level=0]').find('img.has_children').attr('src', '__STATIC__/admin/images/tv-collapsable-last.gif').trigger('click');
                    $('tr[class^=pid_]').removeClass('trSelected');
                    $(obj).attr('data-status', 'close').attr('title','展开所有子栏目').attr('src','__STATIC__/admin/images/tv-expandable.gif');
                }

                setCookies('admin-treeClicked', status);
                return false;
            }
            function setCookies(name, value, time)
            {
                var cookieString = name + "=" + escape(value) + ";";
                if (time != 0) {
                    var Times = new Date();
                    Times.setTime(Times.getTime() + time);
                    cookieString += "expires="+Times.toGMTString()+";"
                }
                document.cookie = cookieString+"path=/";
            }
            var src = $(obj).attr('src');
            if(src == '__STATIC__/admin/images/tv-expandable.gif')
            {
                // $("#treet1 tr").removeClass('tb_child');
                // $(".pid_"+id).addClass('tb_child');
                $(".pid_"+id).show();
                $(obj).attr('src','__STATIC__/admin/images/tv-collapsable-last.gif');
                var status = 'close';
            }else{
                $(obj).attr('src','__STATIC__/admin/images/tv-expandable.gif');
                var status = 'open';

                // 如果是点击减号, 遍历循环他下面的所有都关闭
                var tbl = document.getElementById("arctype_table");
                cur_tr = obj.parentNode.parentNode.parentNode;
                var fnd = false;
                for (i = 0; i < tbl.rows.length; i++)
                {
                    var row = tbl.rows[i];

                    if (row == cur_tr)
                    {
                        fnd = true;
                    }
                    else
                    {
                        if (fnd == true)
                        {

                            var level = parseInt($(row).data('level'));
                            var cur_level = $(cur_tr).data('level');

                            if (level > cur_level)
                            {
                                $(row).hide();
                                $(row).find('img.has_children').attr('src','__STATIC__/admin/images/tv-expandable.gif');
                            }
                            else
                            {
                                fnd = false;
                                break;
                            }
                        }
                    }
                }
            }
            setCookies('admin-treeClicked', status);
        }


        function delfun(obj){
            var title = $(obj).attr('data-name');
            layer.confirm('<font color="#ff0000">如有子栏目及文档将一起清空</font>，确认删除？', {
                title: title,
                btn: ['确定','取消'] //按钮
            }, function(){
                // 确定
                $.ajax({
                    type : 'post',
                    url : $(obj).attr('data-url'),
                    data : {id:$(obj).attr('data-id')},
                    dataType : 'json',
                    success : function(data){
                        layer.closeAll();
                        if(data.status == 1){
                            layer.msg(data.msg, {icon: 1});
                            window.location.reload();
                            // $('tr[data-id="'+$(obj).attr('data-id')+'"]').remove();
                        }else{
                            layer.alert(data.msg, {icon: 2});  //alert(data);
                        }
                    }
                })
            }, function(index){
                layer.close(index);
            });
            return false;
        }
    </script>
</div>






{/block}
{block name="js"}
<script type="text/javascript" src="__STATIC__/admin/js/treemenu.js"></script>
<script>
    $(function(){
        // 菜单栏目调用开启
        $(".tree").treemenu({delay:300}).openActive();
        // 菜单栏目,父类发布功能不能操作
        $('.tree').find('.tree-closed > span:nth-child(1)').find('.tree-option a.btn-success').css({'color':'#eee','background':'#fff','border':'1px solid #ddd',"cursor":"default"}).removeAttr('onclick');
        // 菜单栏目,父类删除功能不能操作
        $('.tree').find('.tree-closed > span:nth-child(1)').find('.tree-option a.btn-danger').css({'color':'#eee','background':'#fff','border':'1px solid #ddd',"cursor":"default"}).removeAttr('onclick');

    });
</script>

<script type="text/javascript">

    $("button").hide();

    $("tr.va-m").hide();
    $("[title=0]").show();

    $(document).ready(function(){
        $("button").click(function(){
            var num=($(this).attr('value'));
            $("[title="+num+"]").toggle();
            if($(this).text()==="-"){
                $(this).html('+');
            }else{
                $(this).html('-');
            }
        });
    })

    $("tr.va-m").each(function(){
        if($(this).attr('title')!='0'){
            var nn=$(this).attr('title');
            $("[value="+nn+"]").show();
        }
    });
/*
    {volist name="nav_model" id="vv"}
    $(".{$key}").html("{$vv}");
    {/volist}
*/
    $(".about").html("<font color=\"#FF0000\">单页面</font>");

        function tijiao(url, id,status,obj) {
            if($(obj).hasClass('label-danger')){
                $(obj).html("恢复");
                $(obj).removeClass('label-danger').addClass('label-success');
                url= '{:url(\''.\\think\\Request::instance()->controller().'/forbid')}';
            }else {
                $(obj).removeClass('label-success').addClass('label-danger');
                $(obj).html("禁用");
                url= '{:url(\''.\\think\\Request::instance()->controller().'/resume')}';
            }
            $.post(url, {id: id}, function (data) {
                //没有权限返回信息
                if(data.code=='0'){
                    layer.alert(data.msg);
                }
            }, 'json')
        }
</script>
{/block}